package com.github.aloxc.plugin.restplus.listener;

import com.github.aloxc.plugin.restplus.i18n.I18Bundle;
import com.github.aloxc.plugin.restplus.navigator.RestServiceDetail;
import com.intellij.openapi.util.IconLoader;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class ToolsListener extends MouseAdapter {
    private RestServiceDetail myRestServiceDetail;

    public ToolsListener(RestServiceDetail myRestServiceDetail) {

        this.myRestServiceDetail = myRestServiceDetail;
    }

    @Override
    public void mouseClicked(MouseEvent event) {

        int x = event.getX();
        int y = event.getY() + 18;
        JPopupMenu menu = new JPopupMenu();

        //另存为
        JMenuItem item = new JMenuItem(I18Bundle.getMessage("com.github.aloxc.plugin.restplus.toolbar.tools.jwt.text"));
        item.setIcon(IconLoader.getIcon("/icons/jwt.png"));
        item.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        item.addActionListener(new JWTActionListener(myRestServiceDetail.getProject()));
        menu.add(item);

        item = new JMenuItem(I18Bundle.getMessage("com.github.aloxc.plugin.restplus.toolbar.tools.sql.text"));
        item.setIcon(IconLoader.getIcon("/icons/SQL.png"));
        item.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
//            item.addActionListener(new SelectEnvironmentListener(project));
//            menu.add(item);

        item = new JMenuItem(I18Bundle.getMessage("com.github.aloxc.plugin.restplus.toolbar.tools.json.text"));
        item.setIcon(IconLoader.getIcon("/icons/json.png"));
        item.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        item.addActionListener(new JsonToolActionListener(myRestServiceDetail.getProject()));
        menu.add(item);
        menu.show((JButton) event.getSource(), x, y);
    }
}
